package demo

import "com/study/util"

type LinkList struct {
	obj  interface{}
	next *LinkList
}

func (receiver *LinkList) Add(node interface{}) {
	if node == nil {
		return
	}
	if receiver.next != nil {
		receiver.next.Add(node)
		return
	}
	receiver.next = &LinkList{
		next: nil,
		obj:  &node,
	}
}

func (receiver *LinkList) Get(index int) *LinkList {
	if index != 0 {
		if receiver.next == nil {
			return nil
		}
		return receiver.next.Get(index - 1)
	}
	return receiver
}

func LinkListDemo() {
	list := LinkList{}
	list.Add(123)
	list.Add(456)
	list.Add("受到广泛")
	list.Add("sdf")
	current := list
	for {
		util.PrnType(current.obj)
		if current.next == nil {
			break
		}
		current = *current.next
	}
}
